Non-record: Focal Loss (gamma=2.0) — val_bpb=1.1460#1233
Open
ibarrajo wants to merge 1 commit intoopenai:mainfrom
Open
Non-record: Focal Loss (gamma=2.0) — val_bpb=1.1460#1233ibarrajo wants to merge 1 commit intoopenai:mainfrom
ibarrajo wants to merge 1 commit intoopenai:mainfrom
Conversation
…460) Replaces standard cross-entropy with focal loss (1-p)^2 * CE during training to down-weight easy tokens and focus gradient on hard tokens. Built on Approach B (Int5 GPTQ + 33.6M params). Focal loss at gamma=2.0 hurts BPB by +0.028 vs baseline, suggesting the technique over-suppresses gradients from well-predicted tokens that still carry useful signal. Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
(1-p)^gamma * CEwith gamma=2.0 replaces standard cross-entropy during training, down-weighting easy tokens to focus gradient signal on hard tokens(1-p)^2among other techniquesResults
Delta: +0.028 BPB vs baseline — focal loss hurts at gamma=2.0.
Analysis: Why Focal Loss Hurts
Focal loss at gamma=2.0 over-suppresses gradients from well-predicted tokens. In language modeling (unlike object detection where focal loss originated), even "easy" tokens carry useful distributional signal. The
(1-p)^2factor reduces their gradient contribution too aggressively, slowing overall learning. A lower gamma (0.5-1.0) or curriculum-style scheduling might work better, but was not explored.Key Changes
forward():loss = ((1 - (-ce).exp()).pow(gamma) * ce).mean()FOCAL_GAMMAenv var (default 2.0, set to 0.0 for standard CE)Rule Compliance
Test Plan
🤖 Generated with Claude Code